package com.zwl.sjzmanagement.controller;

import com.atguigu.tingshu.common.result.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zwl.model.Armors;
import com.zwl.sjzmanagement.service.ArmorsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/armors")
public class ArmorsController {

    @Autowired
    private ArmorsService armorsService;



    //armorsList查看所有防具armors
//api/armors/armorsList
    @GetMapping("/armorsList")
    public Result getArmorsList(@RequestParam(defaultValue = "1") Long pn, @RequestParam(defaultValue = "10") Long pz) {

        IPage<Armors> page = new Page<>(pn,pz );


        List<Armors> armors = armorsService.getArmorsList(page);
        page.setRecords(armors);
//        System.out.println(page);
        return Result.ok(page);

    }

    @GetMapping("/getArmorById/{id}")
    public Result getArmorsList(@PathVariable Long id) {

        Armors armor = armorsService.getById(id);
        return Result.ok(armor);

    }

//    http://localhost:8001/api/armors/armorsAdd
    @PostMapping("/armorsAddOrUpdate")
    public Result armorsAddOrUpdate(@RequestBody Armors armors) {

        //根据id判断，相同则执行跟新操作
        armorsService.saveOrUpdate(armors);

        return Result.ok();

    }

//    http://localhost:8001/api/armors/armorsDelById
    @DeleteMapping("/armorsDelById/{id}")
    public Result armorsDelById(@PathVariable Integer id) {

        armorsService.removeById(id);

        return Result.ok();

    }

    @PostMapping("/armorsBatchDelById")
    public Result armorsBatchDelById(@RequestBody List<Integer> ids) {

        //根据id判断，相同则执行跟新操作
        armorsService.removeBatchByIds(ids);

        return Result.ok();

    }

}
